<?php

include(dirname(__FILE__) . '/../../bootstrap/functional.php');

$browser = new TrueTraderTestFunctional(new sfBrowser());
$browser->loadData()->restart();

$browser->
  info('1 - User registrationw user')->
  info('  1.1 - Submit a user with only empty field')->
  get('/register')->
  with('request')->begin()->
    isParameter('module', 'sfGuardRegister')->
    isParameter('action', 'index')->
  end()->
  click('Inscription', array('user' => array(
          'first_name' => '',
          'last_name' => '',
          'username' => '',
          'email_address' => '',
          'password' => '',
          'password_again' => ''
          )), array('position' => 2))->
  with('form')->begin()->
    hasErrors(6)->
      isError('first_name', 'required')->
      isError('last_name', 'required')->
      isError('username', 'required')->
      isError('email_address', 'required')->
      isError('password', 'required')->
      isError('password_again', 'required')->
  end()->

  info('  1.2 - Submit a user with a too short username, password and a wrong email')->
  with('request')->begin()->
    isParameter('module', 'sfGuardRegister')->
    isParameter('action', 'index')->
  end()->
  click('Inscription', array('user' => array(
          'first_name' => 'Tester',
          'last_name' => 'Tester',
          'username' => 'aze',
          'email_address' => 'not.an.email',
          'password' => '123456',
          'password_again' => '123456'
          )), array('position' => 2))->
  with('form')->begin()->
    hasErrors(4)->
      isError('username', 'min_length')->
      isError('email_address', 'invalid')->
      isError('password', 'min_length')->
      isError('password_again', 'min_length')->
  end()->
        
  info('  1.3 - Submit a user with a different password')->
  with('request')->begin()->
    isParameter('module', 'sfGuardRegister')->
    isParameter('action', 'index')->
  end()->
  click('Inscription', array('user' => array(
          'first_name' => 'Tester',
          'last_name' => 'Tester',
          'username' => 'test',
          'email_address' => 'an@email.com',
          'password' => '1234567',
          'password_again' => '1234568'
          )), array('position' => 2))->
  with('form')->begin()->
    hasErrors(1)->
      isError('password', 'invalid')->
  end()->

  info('  1.4 - Submit a valid user')->
  with('request')->begin()->
    isParameter('module', 'sfGuardRegister')->
    isParameter('action', 'index')->
  end()->
  click('Inscription', array('user' => array(
          'first_name' => 'Tester',
          'last_name' => 'Tester',
          'username' => 'test',
          'email_address' => 'an@email.com',
          'password' => '1234567',
          'password_again' => '1234567'
          )), array('position' => 2))->

  with('form')->begin()->
    hasErrors(false)->
  end()->

  with('response')->isRedirected()->followRedirect()->
  with('request')->begin()->
    isParameter('module', 'article')->
    isParameter('action', 'index')->
  end()
;